//
//  HomeCustomBtn.m
//  BaseProject
//
//  Created by hundredsandc on 2017/10/26.
//  Copyright © 2017年 hundredsandc. All rights reserved.
//

#import "HomeCustomBtn.h"
#import "Masonry.h"

@interface HomeCustomBtn ()
@property (nonatomic,strong)UIImageView *leftImageView;
@property (nonatomic,strong)UILabel *MainTitleLabel;
@property (nonatomic,strong)UILabel *subTitleLabel;
@property (nonatomic,assign)BOOL isleft;

@end

@implementation HomeCustomBtn

-(instancetype)initWithFrame:(CGRect)frame title:(NSString *)title subTitle:(NSString *)subTitle imageUrlStr:(NSString *)urlStr isLeft:(BOOL)isLeft{

    self = [super initWithFrame:frame];
    if (self) {
        self.leftImageView.image = [UIImage imageNamed:urlStr];
        self.MainTitleLabel.text = title;
        self.subTitleLabel.text = subTitle;
        self.isleft = isLeft;
        self.backgroundColor = [DFColor bgGrayColor];
        
        [self addSubview:_leftImageView];
        [self addSubview:_MainTitleLabel];
        [self addSubview:_subTitleLabel];
        [self addConstraint];
        
    }
    return self;
}
-(void)addConstraint{
    WS(ws);
    [_leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (self.isleft) {
            make.left.equalTo(ws).with.offset(40);
        }else{
            make.left.equalTo(ws).with.offset(35);
        }
        make.width.mas_equalTo(@27.5);
        make.height.mas_equalTo(@27.5);
        make.centerY.equalTo(ws.mas_centerY);
    }];
    
    [_MainTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_leftImageView.mas_right).with.offset(10);
        make.top.equalTo(ws).with.offset(20);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(16);
    }];

    [_subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_MainTitleLabel);
        make.top.equalTo(_MainTitleLabel.mas_bottom).with.offset(7);
        make.width.mas_equalTo(120);
        make.height.mas_equalTo(11);
    }];
}
-(UIImageView *)leftImageView{
    if (!_leftImageView) {
        _leftImageView = [[UIImageView alloc]init];
    }
    return _leftImageView;
}
-(UILabel *)MainTitleLabel{
    if (!_MainTitleLabel) {
        _MainTitleLabel = [[UILabel alloc]init];
        _MainTitleLabel.font = FONT(16);
        _MainTitleLabel.textColor = [DFColor textBlack];
    }
    return _MainTitleLabel;
}
-(UILabel *)subTitleLabel{
    if (!_subTitleLabel) {
        _subTitleLabel = [[UILabel alloc]init];
        _subTitleLabel.font = FONT(11);
        _subTitleLabel.textColor = [DFColor textGray];
    }
    return _subTitleLabel;
}



@end
